﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.CraftRoutes
{
    public class CraftRouteBackHandler : IRequestHandler<CraftRouteBackCommand, ResultsDTO<CraftRoute>>
    {
        private readonly IBateRepository<CraftRoute> craftroute;
        public CraftRouteBackHandler(IBateRepository<CraftRoute> craftroute)
        {
            this.craftroute = craftroute;   
        }
        public async Task<ResultsDTO<CraftRoute>> Handle(CraftRouteBackCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO<CraftRoute>() { Code = 0 };


            var str = "select * from craftroute where routeId=" + request.RouteId + "";

            var per = new CraftRoute();

            DapperHelper dapperHelper = new DapperHelper();

            list.Data = craftroute.GetAll(str, per, dapperHelper.MangoMesRead).ToList();


            return list;
        }
    }
}
